<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Site/classes/PhpFox_ComponentEditBanList.class.php, $Author:  $ */

/** Component for editing ban lists
 * @version $Id: PhpFox_ComponentEditBanList.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 * @package module.site
 *
 */
class PhpFox_Mod_Site_ComponentEditBanList extends BaseComponent
{
    function process()
    {
        $oReq = &App::getRequest();
        $oTpl = &$this->_oModule->getTemplate();

 		$iPage = $oReq->get('page', 1);
        $iPageSize = App::getParam('admin.pagesize');

        $oSecurityService = &App::getModuleService('Account', 'Security');
        /* @var $oSecurityService PhpFox_Mod_Account_ServiceSecurity */
        if (!$oSecurityService->hasStaffPerm('MENU_deny'))
        {
            App::gotoUrl('admin.main');
        }

		$sType = $oReq->get('type');

		if ( !$sType )
		{
			return '';
		}

		if ( $oReq->get('delete') )
		{
			$aDeletes = $oReq->getArray('item');

			if ( count($aDeletes) > 0 )
			{
				foreach($aDeletes as $iId)
				{
					$this->oDatabase->_delete(App::getT('ban'), " banid = '". $iId ."' ");
				}
				App::rmCache('ban_word.php');
				App::gotoUrl('admin.ban', array('type' => $sType, 'page' => $iPage), App::format('Mod_Site.ban_deleted'), false);
			}
		}

        if ( $sAdd = $oReq->get('add') )
        {
			$aQuery = array
			(
				'type' => $sType,
				'value' => $sAdd,
				'replace' => $oReq->get('replace'),
				'user_id' => App::getUser('id'),
				'time' => time(),
			);

			$this->oDatabase->insert(App::getT('ban'), $aQuery);
			App::rmCache('ban_word.php');
            App::gotoUrl('admin.ban', array('type' => $sType, 'page' => $iPage), App::format('Mod_Site.ban_added'), false);
        }

	    $iCnt = $this->oDatabase->getField("SELECT COUNT(*) FROM ". App::getT('ban') ." WHERE type = '". $sType ."'");

		$iOffset = $this->oDatabase->_getPageNum($iPage, $iPageSize, $iCnt);

		$aItems = $this->oDatabase->getRows("SELECT b.banid, b.type, b.value, b.replace, b.time, u.user FROM
			". App::getT('ban') ." AS b
			LEFT JOIN ". App::getT('user') ." AS u ON(b.user_id = u.id)
			WHERE b.type = '". $sType ."'
			LIMIT ". $iOffset .",". $iPageSize ."");

        $oPager = App::newObject('Pager', $iCnt, $iPage, $iPageSize);

        $oTpl->assign(array(
            'aErrors'    => $this->getErrors(),
            'aItems'   => $aItems,
            'aPaging'   => $oPager->getInfo(App::getUrl()),
            'sType' => $sType,
        ));

        return $oTpl->fetch('EditBanList.html');
    }
}
?>